package ch09_;

public class StringPermutation {
	public void permute(String s) {
		char[] seq = s.toCharArray();
		permute(seq, 0);
	}
	private void permute(char[] seq, int p) {
		if (p == seq.length) {
			System.out.println(seq);
		}
		for (int i = p; i < seq.length; i++) {
			swap(seq, i, p);
			permute(seq, p + 1);
			swap(seq, p, i);
		}
	}
	
	private void swap(char[] seq, int i, int j) {
		char tmp = seq[i];
		seq[i] = seq[j];
		seq[j] = tmp;
	}
	
	public static void main(String[] args) {
		StringPermutation test = new StringPermutation();
		String s = "abc";
		test.permute(s);
	}
}
